import pygame


class Dragon(pygame.sprite.Sprite):
    def __init__(self, img, dims=(720, 1280), size=(200, 200), position=(200, 400)):
        super().__init__()
        self.dims = dims
        self.width, self.height = dims
        self.image = pygame.transform.scale(img, size)
        self.rect = self.image.get_rect()
        self.position = position
        self.rect = (position[0], position[1])
        self.speed_x = 4
        self.moveLength = 0
        self.jumped = False
        self.curpos = "botton"

    def update(self):
        y_move = 0

        if self.jumped is True:
            if self.curpos == "botton": #如果在底部
                if self.rect[1] > self.position[1]-200:
                    self.vel_y = -3
                else:
                    self.curpos = "top"
            if self.curpos == "top": #如果在顶部
                if self.rect[1] < self.position[1]:
                    # 添加角色重力（跳跃之后自然下落）
                    self.vel_y += 0.3
                    if self.vel_y > 3:
                        self.vel_y = 3
                else:
                    self.vel_y = 0
                    self.curpos = "botton"
                    self.jumped = False

            y_move += self.vel_y
            self.rect = (self.rect[0], self.rect[1] + y_move)
            #判断，如果位置在最下面面，跳跃结束
            # if self.rect[1] > self.position[1]:
            #     self.jumped = False


    def draw(self, screen):
        screen.blit(self.image, self.rect)
